#include "main.h"

#define CNT_HIGH  12

#define CNT_LOW  138



Valve_T tValve_left;
Valve_T tValve_right;

void Valve_Init(void)
{
	tValve_left.Cnt =0;
	tValve_left.eValve_Sta =Valve_OPEN;
	
	tValve_right.Cnt =0;
	tValve_right.eValve_Sta =Valve_OPEN;
	
	Deal_ValveLeft_OPEN();
	Deal_ValveRight_OPEN();
}


void f_flowValve(void)
{
  switch (tValve_left.eValve_Sta)
	{
		case Valve_CLOSE:
			
			tValve_left.Cnt ++;
		
			if(tValve_left.Cnt <=CNT_HIGH)
			{
				DO_out_Set(DO_ID_LEFTCOIL_TUBE,1 );
				
			}
			else
			{
				DO_out_Set(DO_ID_LEFTCOIL_TUBE,0 );
				if(tValve_left.Cnt >=(CNT_HIGH+CNT_LOW))
				{
						tValve_left.Cnt =0;
				}
			}
			break;
				
		default:
				break;
	
	}
	
	switch (tValve_right.eValve_Sta)
	{
		case Valve_CLOSE:
			
		 tValve_right.Cnt ++;
		
			if(tValve_right.Cnt <=CNT_HIGH)
			{
			 DO_out_Set(DO_ID_RIGHTCOIL_TUBE, 1);
			}
			else
			{
				DO_out_Set(DO_ID_RIGHTCOIL_TUBE, 0);
				if(tValve_right.Cnt >=(CNT_HIGH+CNT_LOW))
				{
						tValve_right.Cnt =0;
				}
			}
			break;
				
		default:
				break;
	
	}
}

void Deal_ValveLeft_OPEN(void)
{
 	tValve_left.Cnt =0;
	tValve_left.eValve_Sta =Valve_OPEN;
	DO_out_Set(DO_ID_LEFTCOIL_TUBE,1);
}

void Deal_ValveRight_OPEN(void)
{
	tValve_right.Cnt =0;
	tValve_right.eValve_Sta =Valve_OPEN;
	DO_out_Set(DO_ID_RIGHTCOIL_TUBE,1);
}
